import java.util.Arrays;

public class Solution1402 {
    public int maxSatisfaction(int[] satisfaction) {
        Arrays.sort(satisfaction);
        int[] sum=new int[satisfaction.length];
        sum[satisfaction.length-1]=satisfaction[satisfaction.length-1];
        for (int i=sum.length-2;i>=0;i--){
            sum[i]=sum[i+1]+satisfaction[i];
        }
        int ans=0;
        int max=0;
        for (int i=satisfaction.length-1;i>=0;i--){
            ans=ans+sum[i];
            max=Math.max(max,ans);
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1402().maxSatisfaction(new int[]{-1,-8,0,5,-9}));
    }
}
